<dt id="contentHeaderPanel" class="panel">
  <span class="content">
    <%= link_to button_text(:upload), "#", :id => "toggleUploadPanel", :class => "button small right" if current_user.allow?(:media_file_create) %>
    <%= t(:files_in, :directory => @dir.name, :scope => [:media, :dirs, :show]) %>
  </span>
</dt>
<dd id="contentBodyPanel">
  <div id="contentInfoPanel" data-panel-hidden="true">
    <%= render :partial => "skyline/media/files/new" %>
  </div>
  <div id="contentEditPanel">
    <%= render :partial => "skyline/media/files/index" %>
  </div>
</dd>
<script type="text/javascript" charset="utf-8">
  (function(){
    var panel = $('contentPanel').retrieve("skyline.layout");
    if(panel){ panel.restore(); panel.setup(); }
    
    var tree = $('dirtree').retrieve("skyline.tree");
    if(tree && tree.selectedNode && tree.selectedNode.getParent().get("id") != "dirItem_<%= @dir.id %>"){
      tree.selectNode(null, $('dirItem_<%= @dir.id %>').getChildren("a")[0]);
    } 
        
    $("toggleUploadPanel").addEvent("click",function(){ 
      var panel = $('contentInfoPanel');
      var l = panel.retrieve('skyline.layout');
      var u = panel.retrieve('application.uploader');
      
      if(l.hidden){
        l.show();    
        if(u){
          u.uploader.refresh();
        }
      } else {
        l.hide();
      }
    }.bind(this));
  })();
</script>